Skip to content

Add table delete/truncate confirmation dialog#11

Merged
datlechin merged 11 commits intomainfrom
feat/table-operation-dialog
Dec 27, 2025
Merged

Add table delete/truncate confirmation dialog#11
datlechin merged 11 commits intomainfrom
feat/table-operation-dialog

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

  • Add TablePlus-like confirmation dialog for table delete/truncate operations
  • Support "Ignore foreign key checks" and "Cascade" options
  • Generate database-specific SQL for MySQL, PostgreSQL, and SQLite

Test plan

  • Right-click table → Delete → Verify dialog appears
  • Right-click table → Truncate → Verify dialog appears
  • Press ESC to cancel dialog
  • Press Enter/OK to confirm
  • Test with "Ignore foreign key checks" enabled
  • Test with "Cascade" enabled (PostgreSQL)
  • Verify SQL generation for each database type

Implement TablePlus-like confirmation dialog for delete/truncate table
operations with options for:
- Ignore foreign key checks
- Cascade (delete dependent rows)

Database-specific SQL generation:
- MySQL/MariaDB: SET FOREIGN_KEY_CHECKS=0/1
- PostgreSQL: CASCADE keyword, session_replication_role
- SQLite: PRAGMA foreign_keys
Copilot AI review requested due to automatic review settings December 26, 2025 15:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a TablePlus-style confirmation dialog for table delete and truncate operations with support for database-specific options like ignoring foreign key checks and cascade operations. The implementation integrates across multiple layers including UI dialog, sidebar integration, coordinator SQL generation, and session state management.

Key Changes:

  • New confirmation dialog component with database-specific option handling
  • SQL generation for MySQL, PostgreSQL, and SQLite with foreign key and cascade support
  • Session-level tracking of operation options for each table

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
TablePro/Models/TableOperationOptions.swift Defines data models for operation options and operation types
TablePro/Models/ConnectionSession.swift Adds tableOperationOptions dictionary to session state
TablePro/Views/Sidebar/TableOperationDialog.swift New SwiftUI dialog component with database-specific option controls
TablePro/Views/Sidebar/SidebarView.swift Integrates dialog presentation and manages operation confirmation flow
TablePro/Views/MainContentView.swift Threads tableOperationOptions binding through view hierarchy
TablePro/Views/Main/MainContentNotificationHandler.swift Passes tableOperationOptions to coordinator's saveChanges
TablePro/Views/Main/MainContentCoordinator.swift Generates database-specific SQL with FK disable/enable and cascade options
TablePro/ContentView.swift Adds session binding for tableOperationOptions and passes databaseType to sidebar

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift Outdated
Comment thread TablePro/Models/TableOperationOptions.swift Outdated
Comment thread TablePro/Views/Sidebar/SidebarView.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift Outdated
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift
- Wrap multiple operations in BEGIN/COMMIT transaction for atomicity
- Sort tables alphabetically for consistent execution order
- Use SET CONSTRAINTS ALL DEFERRED for PostgreSQL (no superuser required)
- PostgreSQL constraints auto-check at COMMIT
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Sidebar/SidebarView.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift
Comment thread TablePro/Models/TableOperationOptions.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Sidebar/SidebarView.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
- Rename TableOperationType.delete to .drop for clarity
- Reset dialog state (ignoreForeignKeys, cascade) on open
- Restore pending operations on failure for retry capability
- Include SQLite in transaction wrapping
- Rename 'opts' variable to 'tableOptions' for readability
- Add note when multiple tables selected (same options apply to all)
- Use SET CONSTRAINTS ALL DEFERRED for PostgreSQL (no superuser required)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift
Comment thread TablePro/Views/Sidebar/SidebarView.swift
- Fix PostgreSQL FK handling: return empty array for FK statements
  (PostgreSQL doesn't have a simple way to disable FK checks globally,
  rely on CASCADE option instead)
- Add FK re-enable on error in catch block for MySQL/SQLite
- Add sqlite_sequence reset for true TRUNCATE semantics (reset auto-increment)
- Add docstrings to helper functions for better code documentation
- Fix nested transaction issue when both cell changes and table ops exist
  (wrap in single transaction only when multiple operation types)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Main/MainContentCoordinator.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift Outdated
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift Outdated
Comment thread TablePro/Views/Main/MainContentCoordinator.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift
- Fix SQL injection: escape embedded quotes in quoteIdentifier by
  doubling them (SQL standard escaping)
- Move FK disable/enable statements outside transaction boundary to
  ensure they take effect even on rollback
- Rename dropTableStatement parameter from tableName to quotedName
  for consistency with truncateStatements
- Disable "Ignore foreign key checks" option for PostgreSQL with
  explanation text (use CASCADE instead)
- Add onChange handlers to reset cascade/ignoreForeignKeys when their
  toggles become disabled, preventing silent override of user selection
- Simplify confirmAndDismiss since values are now reset when disabled
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 17 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Sidebar/SidebarView.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift Outdated
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift Outdated
Comment thread TablePro/Views/Sidebar/TableOperationDialog.swift
Comment thread TablePro/Views/Main/MainContentCoordinator.swift Outdated
datlechin and others added 6 commits December 27, 2025 10:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@datlechin datlechin merged commit 92393e3 into main Dec 27, 2025
@datlechin datlechin deleted the feat/table-operation-dialog branch December 29, 2025 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants